﻿@inject IDataCacheService _dataCatcheService


<MDCard Href="@GetLink()" Class=" pa-3 pt-2 pb-2" Target="_blank">
    <div class="" style="height: 100%; align-content: center;display:flex;">
        @if (string.IsNullOrWhiteSpace(GetImage()))
        {
            <div style="display: flex; flex-direction: column; justify-content: center;">
                <div class="text-truncate-2  title-large">
                   @GetName()
                </div>
                <div class="text-truncate-3 label-large">
                    @GetValue()
                </div>
            </div>
        }
        else
        {
            if (_dataCatcheService.IsApp)
            {
                <div style=" display: flex; flex-direction: column; justify-content: center;">
                    <img src="@GetImage()" style="width: 50px;" alt="@GetName()" />
                </div>
                <div class="ps-3" style="display: flex; flex-direction: column; justify-content: center;">
                    <div class="text-truncate-2 title-large">
                        @GetName()
                    </div>
                    <div class="text-truncate-3 label-large">
                        @GetValue()
                    </div>
                </div>
            }
            else
            {
                <div style=" display: flex; flex-direction: column; justify-content: center;">
                    <img src="@GetImage()" style="width: 50px;" alt="@GetName()" />
                </div>
                <div class="ps-3" style="display: flex; flex-direction: column; justify-content: center;">
                    <div class="text-truncate-2 title-large">
                        @GetName()
                    </div>
                    <div class="text-truncate-3 label-large">
                        @GetValue()
                    </div>
                </div>
            }
        }
    </div>
</MDCard>

@code {
    [Parameter]
    public RelevancesKeyValueModel Model { get; set; }
    [Parameter]
    public bool IsVideo { get; set; }

    public string GetImage()
    {
        var image= Model.DisplayName switch
        {
            "萌娘百科" => "Moegirl.png",
            "Bangumi" => "Bangumi.png",
            "百度百科" => "BaiDuWiki.png",
            "2DFan" => "2DFan.png",
            "中文维基百科" => "Wiki.png",
            "月幕Galgame" => "YMGal.png",
            "Bilibili" => "bilibili.png",
            "bilibili" => "bilibili.png",
            "WikiData" => "Wikidata.png",
            "微博" => "weibo.png",
            "AcFun" => "AcFun.png",
            "知乎" => "zhihu.png",
            "爱发电" => "Afdian.png",
            "Pixiv" => "pixiv.png",
            "Twitter" => "twitter.png",
            "YouTube" => "Youtube.png",
            "Facebook" => "Facebook.png",
            "官网" => "SmartHome.png",
            "摩点" => "modian.png",
            "小黑盒" => "xiaoheihe.jpg",
            _ => null
        };

        if(string.IsNullOrWhiteSpace(image))
        {
            return null;
        }

        return "https://res.cngal.org/_content/CnGalWebSite.Shared/images/" + image;
    }

    public string GetValue()
    {
        return Model.DisplayName switch
        {
            "VNDB" => Model.DisplayValue + (string.IsNullOrWhiteSpace(Model.DisplayValue) ? "" : " - ") + "VNDB.org力争成为一个关于视觉小说的全面的信息数据库",
            _ => Model.DisplayValue
        };
    }

    public string GetName()
    {
        return Model.DisplayName switch
        {
            "bilibili" => IsVideo ? "前往 bilibili 观看" : Model.DisplayName,
            _ => Model.DisplayName
        };
    }


    public string GetLink()
    {
        return Model.DisplayName switch
        {
            "月幕Galgame" => Model.Link.Replace("www.ymgal.com", "www.ymgal.games"),
            _ => Model.Link
        };
    }
}
